package cn.net.yugu.doraemon.api.common.enums;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

public interface BaseEnum<C> {

  /**
   * 获取枚举code
   *
   * @return
   */
  C getCode();


  /**
   * 描述
   *
   * @return
   */
 default String getDesc(){
     throw new UnsupportedOperationException();
 }


  static <E extends BaseEnum<C>, C> Optional<E> of(E[] values, C code) {
    return Arrays.stream(values)
            .filter(baseEnum -> Objects.equals(code, baseEnum.getCode()))
            .findFirst();
  }
}
